package zhoug.common.base;

import android.content.pm.ActivityInfo;
import android.os.Bundle;

import zhoug.common.utils.ToastUtils;

import androidx.annotation.LayoutRes;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

/**
 * @Author HK-LJJ
 * @Date 2019/11/28
 * @Description
 */
public abstract class AbsActivity extends AppCompatActivity {
    protected static final String TAG = ">>>AbsActivity";


    /**
     *  @deprecated 请通过 {@link #getActivity()}获取
     */
    @Deprecated
    protected AppCompatActivity mSelf;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        onCreateInit(savedInstanceState);
    }

    protected void onCreateInit(@Nullable Bundle savedInstanceState) {
        mSelf=this;
        setOrientation();
        beforeLayout();
        setContentView();
        setStatusBar();
        findViews();
        initView();
        addListener();
        onCreateFinish(savedInstanceState);

    }

    protected void setContentView(){
        setContentView(getLayoutResID());
    }

    //设置横竖屏
    protected void setOrientation(){
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//竖屏
    }

    /**
     * 状态栏设置
     */
    protected void setStatusBar() {
        //状态栏透明,且布局占用状态栏
//        StatusBarUtils.transparentStatusBar(this);
        //不给状态栏预留位置
//        StatusBarUtils.setFitsSystemWindows(this, false);
        //添加状态栏占位
//        StatusBarUtils.addStatusPlaceView(this);
    }


    /**
     * 设置布局文件之前执行
     */
    protected void beforeLayout() {
    }

    /**
     * 布局文件id
     *
     * @return
     */
    protected abstract @LayoutRes
    int getLayoutResID();

    /**
     * view初始化
     */
    protected abstract void findViews();

    /**
     * 添加监听
     */
    protected abstract void addListener();

    protected abstract void initView();


    /**
     * onCreate 方法最后调用
     *
     * @param savedInstanceState
     */
    protected abstract void onCreateFinish(@Nullable Bundle savedInstanceState);


    public boolean openEventBus(){
        return false;
    }





    //以下是吐司消息
    protected void toast(Object msg) {
        toastShort(msg);
    }

    //以下是吐司消息
    protected void toastShort(Object msg) {
        ToastUtils.toastShort(getApplicationContext(), msg);
    }

    protected void toastLong(Object msg) {
        ToastUtils.toastLong(getApplicationContext(), msg);
    }

    protected void toastShortCenter(Object msg) {
        ToastUtils.toastShortCenter(getApplicationContext(), msg);
    }

    protected void toastLongCenter(Object msg) {
        ToastUtils.toastLongCenter(getApplicationContext(), msg);
    }


    protected AppCompatActivity getActivity(){
        return this;
    }


}
